#include <iostream>
#include <vector>
#include <map>

using namespace std;

//class Solution1 {
//public:
//    vector<vector<int>> findWinners(vector<vector<int>>& matches) {
//        vector<vector<int>> res(2);
//        map<int, int> mp;
//        for (auto& match : matches)
//        {
//            int winner = match[0]; int loser = match[1];
//            if (!mp.count(winner)) mp[winner] = 0;
//            ++mp[loser];
//        }
//        for (auto& [player, lcnt] : mp)
//        {
//            if (lcnt == 0) res[0].push_back(player);
//            else if (lcnt == 1) res[1].push_back(player);
//        }
//        return res;
//    }
//};

#include<string>

void solve1()
{
    string str; getline(cin, str);
    int code = 0; int n = str.size();
    int cnt = 1; bool flag = true;
    for (int i = 0; i < n; ++i)
    {
        if (str[i] == '-') continue;
        if (i == n - 1)
        {
            code %= 11;
            if ((code == 10 && str[i] != 'X') || (code < 10 && str[i] != code + '0'))
            {
                flag = false;
                if (code == 10) str[i] = 'X';
                else str[i] = code + '0';
                break;
            }
        }
        code += cnt * (str[i] - '0');
        cnt++;
    }
    if (flag)
        cout << "Right" << endl;
    else
        cout << str << endl;
}

#include <queue>

class Solution1
{
public:
    using pii = pair<int, int>;
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { -1,1,0,0 };

    int solve()
    {
        int n, m; cin >> n >> m;
        vector<vector<char>> maze(n, vector<char>(m));
        queue<pii> q;
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < m; ++j)
            {
                cin >> maze[i][j];
                if (maze[i][j] == 'k')
                    q.push({ i,j });
            }
            getchar();
        }

        int mn = 1000; int cnt = 0;
        int cur = 0;
        while (!q.empty())
        {
            int sz = q.size(); cur++;
            while (sz--)
            {
                auto p = q.front();
                int a = p.first;
                int b = p.second;
                q.pop();
                for (int i = 0; i < 4; ++i)
                {
                    int x = a + dx[i]; int y = b + dy[i];
                    if (x >= 0 && x < n && y >= 0 && y < m && maze[x][y] != '*')
                    {
                        if (maze[x][y] == '.')
                        {
                            q.push({ x,y });
                            maze[x][y] = '*';
                        }
                        else if (maze[x][y] == 'e')
                        {
                            mn = min(mn, cur);
                            cnt++;
                            maze[x][y] = '*';
                        }
                    }
                }
            }
        }

        if (cnt)
            cout << cnt << ' ' << mn << endl;
        else
            cout << -1 << endl;

        return 0;
    }
};

class Solution2 {
public:
    int dx[4] = { 0,0,1,-1 };
    int dy[4] = { 1,-1,0,0 };
    int res = 0;

    void dfs(vector<vector<int>>& matrix, int i, int j, vector<int>& path) {
        if (i < 0 || i >= matrix.size() || j < 0 || j >= matrix[0].size() ||
            (!path.empty() && matrix[i][j] <= path.back())) {
            res = res > path.size() ? res : path.size();
            return;
        }
        path.push_back(matrix[i][j]);
        for (int k = 0; k < 4; ++k)
            dfs(matrix, i + dx[k], j + dy[k], path);
        path.pop_back();
    }

    int solve(vector<vector<int> >& matrix) {
        for (int i = 0; i < matrix.size(); ++i) {
            for (int j = 0; j < matrix[0].size(); ++j) {
                vector<int> path;
                dfs(matrix, i, j, path);
            }
        }
        return res;
    }
};

class Solution3 {
public:
    int longestEqualSubarray(vector<int>& nums, int k) {
        int n = nums.size();
        vector<int> g[n + 1];
        for (int i = 0; i < n; ++i) {
            g[nums[i]].push_back(i);
        }
        int ans = 0;
        for (const auto& ids : g) {
            int l = 0;
            for (int r = 0; r < ids.size(); ++r) {
                while (ids[r] - ids[l] - (r - l) > k) {
                    ++l;
                }
                ans = max(ans, r - l + 1);
            }
        }
        return ans;
    }
};